package com.whut.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javassist.bytecode.Descriptor.Iterator;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.JSONWriter;
import org.hibernate.mapping.Map;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;


import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.whut.model.User;
import com.whut.service.UserManager;
import com.whut.service.impl.UserManagerImpl;
import com.whut.util.UtilCommon;
import com.whut.vo.UserRegisterInfo;

public class BasicAction extends ActionSupport implements ModelDriven {

	private UserManager um;
	private List<User> users;  
	private List<User> allUser;
	private User user;
	private String result;
	
	private int page;
	private int rows;
	
	private UserRegisterInfo userInfo = new UserRegisterInfo();
	 
	private HashMap<String, Object> nMap; 
		
	public BasicAction() {  
		//初始化Map对象  
		nMap = new HashMap<String, Object>();  
    }  

		   

	@Override
	public String execute() {
		try {
			nMap.clear();
			System.out.println(page);
			System.out.println(rows);
//			users=um.getUsers();
			allUser=um.getUsers();
			users=um.getUsersByPage(page, rows);
        	System.out.println("正常取出列表");
        	nMap.put("total",um.getTotal(new User()));
        	nMap.put("rows", users);
        	System.out.println(nMap);  
     	
        	UtilCommon.writeJson(nMap); 
       
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("取用户列表发生异常");
			System.out.println(e);
		}		
		return null;
	}
  
	public UserManager getUm() {
		return um;
	}

	//@Resource(name = "userManager")
	public void setUm(UserManager um) {
		this.um = um;
	}

	// @Override
	public Object getModel() {
		// TODO Auto-generated method stub
		return userInfo;
	}
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	

	public UserRegisterInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserRegisterInfo userInfo) {
		this.userInfo = userInfo;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}


	public HashMap<String, Object> getnMap() {
		return nMap;
	}

	public void setnMap(HashMap<String, Object> nMap) {
		this.nMap = nMap;
	}
 
	public int getPage() {
		return page;
	}
 
	public void setPage(int page) {
		this.page = page;
	}
 
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	
	public List<User> getAllUser() {
		return allUser;
	}

	public void setAllUser(List<User> allUser) {
		this.allUser = allUser;
	}
 
}
